package com.group4.rbac.web.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group4.rbac.entity.Permission;
import com.group4.rbac.service.PermissionService;
import com.study.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author cloud
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/rbac/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    /**
     * 权限列表
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<Permission> list(){
        QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
        List<Permission> list = permissionService.list(queryWrapper);
        return new ResponseResult(200,"权限列表",list);
    }

    /**
     * 增加权限
     * @param permission
     * @return
     */
    @PostMapping("add")
    public ResponseResult add(@RequestBody Permission permission){
        ResponseResult<Permission> add = permissionService.add(permission);
        return add;
    }


    /**
     * 修改权限
     * @param permission
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public ResponseResult<Permission> update(@RequestBody Permission permission){
        ResponseResult<Permission> update = permissionService.update(permission);
        return update;
    }

    /**
     * 权限列表
     * @return
     */
    @GetMapping("order")
    public ResponseResult<List<Permission>> order(){
        List<Permission> order = permissionService.order();
        return new ResponseResult<>(200,"权限菜单",order);
    }

}

